using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace FM12XXTest
{
    public partial class Form1 : Form
    {
        [DllImport("E7umf.dll", EntryPoint = "fw_config_card")]
        public static extern Int32 fw_config_card(Int32 icdev, Byte cardtype);


        [DllImport("E7umf.DLL", EntryPoint = "fw_init")]
        public static extern Int32 fw_init(Int16 port, Int32 baud);
        [DllImport("E7umf.DLL", EntryPoint = "fw_exit")]
        public static extern Int32 fw_exit(Int32 icdev);
        [DllImport("E7umf.Dll", EntryPoint = "fw_request")]
        public static extern Int32 fw_request(Int32 icdev, Byte _Mode, ref UInt32 TagType);
        [DllImport("E7umf.DLL", EntryPoint = "fw_anticoll")]
        public static extern Int32 fw_anticoll(Int32 icdev, Byte _Bcnt, ref UInt32 _Snr);
        [DllImport("E7umf.DLL", EntryPoint = "fw_select")]
        public static extern Int32 fw_select(Int32 icdev, UInt32 _Snr, ref Byte _Size);
        [DllImport("E7umf.DLL", EntryPoint = "fw_card")]
        public static extern Int32 fw_card(Int32 icdev, Byte _Mode, ref UInt32 _Snr);
        [DllImport("E7umf.DLL", EntryPoint = "fw_load_key")]
        public static extern Int32 fw_load_key(Int32 icdev, Byte _Mode, Byte _SecNr, ref Byte _NKey);
        [DllImport("E7umf.DLL", EntryPoint = "fw_authentication")]
        public static extern Int32 fw_authentication(Int32 icdev, Byte _Mode, Byte _SecNr);
        [DllImport("E7umf.DLL", EntryPoint = "fw_read")]
        public static extern Int32 fw_read(Int32 icdev, Byte _Adr, ref Byte _Data);
        [DllImport("E7umf.DLL", EntryPoint = "fw_write")]
        public static extern Int32 fw_write(Int32 icdev, Byte _Adr, ref Byte _Data);
        [DllImport("E7umf.DLL", EntryPoint = "fw_halt")]
        public static extern Int32 fw_halt(Int32 icdev);
        [DllImport("E7umf.DLL", EntryPoint = "fw_changeb3")]
        public static extern Int32 fw_changeb3(Int32 icdev, Byte _SecNr, ref Byte _KeyA, ref Byte _CtrlW, Byte _Bk,
                ref Byte _KeyB);
        [DllImport("E7umf.DLL", EntryPoint = "fw_initval")]
        public static extern Int32 fw_initval(Int32 icdev, Byte _Adr, UInt32 _Value);
        [DllImport("E7umf.DLL", EntryPoint = "fw_increment")]
        public static extern Int32 fw_increment(Int32 icdev, Byte _Adr, UInt32 _Value);
        [DllImport("E7umf.DLL", EntryPoint = "fw_readval")]
        public static extern Int32 fw_readval(Int32 icdev, Byte _Adr, ref UInt32 _Value);
        [DllImport("E7umf.DLL", EntryPoint = "fw_decrement")]
        public static extern Int32 fw_decrement(Int32 icdev, Byte _Adr, UInt32 _Value);
        [DllImport("E7umf.DLL", EntryPoint = "fw_restore")]
        public static extern Int32 fw_restore(Int32 icdev, Byte _Adr);
        [DllImport("E7umf.DLL", EntryPoint = "fw_transfer")]
        public static extern Int32 fw_transfer(Int32 icdev, Byte _Adr);
        [DllImport("E7umf.DLL", EntryPoint = "fw_beep")]
        public static extern Int32 fw_beep(Int32 icdev, UInt32 _Msec);
        [DllImport("E7umf.DLL", EntryPoint = "fw_getver")]
        public static extern Int32 fw_getver(Int32 icdev, ref Byte buff);
        [DllImport("E7umf.DLL", EntryPoint = "fw_reset")]
        public static extern Int32 fw_reset(IntPtr icdev, UInt16 _Msec);
        [DllImport("E7umf.dll", EntryPoint = "fw_cpureset")]
        public static extern Int16 fw_cpureset(Int32 icdev, ref Byte rlen, ref Byte rdata);
        [DllImport("E7umf.dll", EntryPoint = "fw_pro_reset")]
        public static extern Int16 fw_pro_reset(Int32 icdev, ref Byte rlen, ref Byte rdata);
        [DllImport("E7umf.dll", EntryPoint = "fw_pro_commandlink")]
        public static extern Int16 fw_pro_commandlink(Int32 icdev, Byte slen, ref Byte sdata,
            ref Byte rlen, ref Byte rdata, Byte ftt, Byte fFG);
        [DllImport("E7umf.dll", EntryPoint = "fw_cpuapdu")]
        public static extern Int16 fw_cpuapdu(IntPtr icdev, Byte slen, ref Byte sdata, ref Byte rlen,
            ref Byte rdata);

        [DllImport("E7umf.DLL", EntryPoint = "hex_a")]
        public static extern void hex_a(ref Byte hex, ref Byte a, Int32 len);
        [DllImport("E7umf.dll", EntryPoint = "a_hex")]
        public static extern void a_hex(ref Byte a, ref Byte hex, Int32 alen);

        //fm1208 functions
        [DllImport("E7umf.dll", EntryPoint = "FWCosSelecteApp")]
        public static extern UInt32 FWCosSelecteApp(Int32 icdev);
        [DllImport("E7umf.dll", EntryPoint = "FWCosCreateKeyFile")]
        public static extern UInt32 FWCosCreateKeyFile(Int32 icdev, short usDirFileID, short usFileID, short uFileLen, int ulGenSec);
        [DllImport("E7umf.dll", EntryPoint = "FWCosAddKey")]
        public static extern UInt32 FWCosAddKey(Int32 icdev, Byte bKeyType, ref Byte pbKeyValue, int ulKeyValueLen);
        [DllImport("E7umf.dll", EntryPoint = "FWCosVerifyKey")]
        public static extern UInt32 FWCosVerifyKey(Int32 icdev, ref Byte pbKey, int ulKeyLen, int ulKeyType);
        [DllImport("E7umf.dll", EntryPoint = "FWCosCreateBinaryFile")]
        public static extern UInt32 FWCosCreateBinaryFile(Int32 icdev, short usDirFileID, short usFileID, short usFileLen, Byte cryptyType, int ulReadSec, int ulUpdateSec, int ulDeleteSec);
        [DllImport("E7umf.dll", EntryPoint = "FWCosUpdateBinaryFile")]
        public static extern UInt32 FWCosUpdateBinaryFile(Int32 icdev, short usFileID, short usOffset, ref Byte pbBinData, short usUpdateLen, Byte cryptyType, ref Byte pProKey, int ulKeyLen);
        [DllImport("E7umf.dll", EntryPoint = "FWCosReadBinaryFile")]
        public static extern UInt32 FWCosReadBinaryFile(Int32 icdev, short usFileID, ref Byte pbBinData, short usOffset, short usReadLen, Byte cryptyType, ref Byte pProKey, int ulKeyLen);
        [DllImport("E7umf.dll", EntryPoint = "FWCosCreateADF")]
        public static extern UInt32 FWCosCreateADF(Int32 icdev, ushort usDirFileID, int ulCreateSec, int ulDeleteSec, ref char pbDirName, Byte ucDirNameLength);
        [DllImport("E7umf.dll", EntryPoint = "FWCosCredit")]
        public static extern UInt32 FWCosCredit(Int32 icdev, Byte ucKeyID, UInt32 value, ref Byte terminalID, ref Byte pbCreditKey, int ulCreditKeyLen);
        [DllImport("E7umf.dll", EntryPoint = "FWCosPurchase")]
        public static extern UInt32 FWCosPurchase(Int32 icdev, Byte ucKeyID, UInt32 value, ref Byte terminalID, ref Byte pbPurchaseKey, int ulPurchaseKeyLen);
        [DllImport("E7umf.dll", EntryPoint = "FWCosGetBalance")]
        public static extern UInt32 FWCosGetBalance(UInt32 icdev, ref UInt32 balance);

        [DllImport("E7umf.dll", EntryPoint = "FWCosDeleteFileSys")]
        public static extern UInt32 FWCosDeleteFileSys(Int32 icdev);



        public Form1()
        {
            InitializeComponent();
        }

        private void btn_test_Click(object sender, EventArgs e)
        {
            Int32 tmphdev = 0;

            tmphdev = fw_init(100, 0);

            if (tmphdev != -1)
            {
                ShowMsg("打开设备成功！");
            }
            else
            {
                ShowMsg("打开设备失败！");
                return;
            }

            fm12xx_test(tmphdev);

        }

        private void ShowMsg(string str)
        {
            listBox1.Items.Add(str);
        }
        private void fm12xx_test(Int32 icdev)
        {
            int status, i;//the state of each operation
            UInt32 uStatus;
            UInt32 sn = new UInt32();
            byte rlen = new byte();
            byte[] rdata = new byte[1024];//the buffer read from a block
            byte[] showData = new byte[34];//hex type data
            uint[] pval = new uint[1];
            byte[] pChVal = new byte[2];
            byte[] pRBuffer = new byte[1024];
            short lenToRW;
            byte[] pWriteBuffer = new byte[1024];

            byte[] pShowBuf = new byte[1024];

            byte[] pExKey = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };//外部认证密钥
            byte[] pFileProKey =  { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };//文件保护密钥
            byte[] pPurchaseKey ={ 0x20, 0x28, 0x9d, 0x08, 0x52, 0xc9, 0x61, 0x60, 0x5b, 0x92, 0xb6, 0x07, 0xca, 0xa3, 0xcc, 0xd9 };//消费密钥
            byte[] pCreditKey ={ 0xda, 0x40, 0x4f, 0x59, 0xe9, 0xf7, 0x30, 0x05, 0xa8, 0xb9, 0x79, 0x35, 0x73, 0xa8, 0xbd, 0x92 };//圈存密钥
            byte[] pPin = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
            byte[] pTerminal = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };//6字节（固定）的终端机编号
            char[] pDirName = { 'a', ' ', 'T', 'e', 's', 't', ' ', 'D', 'i', 'r' };
            string strMsg;

            lenToRW = 0x54;//
            for (i = 0; i < lenToRW; i++) pWriteBuffer[i] = (byte)(i + 3);

            //device reset
            status = fw_reset((IntPtr)icdev, 10);
            if (status != 0)
            {
                ShowMsg("ERROR(" + status.ToString() + "): Device reset failed.\n");
                return;
            }
            ShowMsg("Device reset OK.\n");

            //find card
            status = fw_card(icdev, 1, ref sn);
            if (status != 0)
            {
                ShowMsg("ERROR(" + status.ToString() + "):Find No card.\n");
                return;
            }
            ShowMsg("Find Card: " + sn.ToString());

            //card reset
            status = fw_pro_reset(icdev, ref rlen, ref rdata[0]);
            if (status != 0)
            {
                ShowMsg("ERROR(" + status.ToString() + "): Card reset failed.\n");
                return;
            }
            ShowMsg("Reset ok");


            //选择主应用
            uStatus = FWCosSelecteApp(icdev);
            if (uStatus != 0)
            {
                ShowMsg("FWCosSelecteApp error!\n");
                fw_exit((int)icdev);//断开连接
                return;
            }
            else
            {
                ShowMsg("FWCosSelecteApp ok!\n");
            }

            //建立一个密钥文件，用于存放各种密钥
            uStatus = FWCosCreateKeyFile(icdev,
                (short)0x0000,//所在目录文件标识,主应用为0
                (short)0x0001,//密钥文件标识符
                (short)0x0040,//密钥文件的长度
                0);//在密钥中安装密钥的权限,为0表示可以任意安装密钥
            if (uStatus != 0)
            {
                ShowMsg("FWCosCreateKeyFile error!\n");
                ShowMsg(uStatus.ToString());
                FWCosDeleteFileSys(icdev);//测试结束前删除这个应用
                fw_exit((int)icdev);//断开连接
                return;

            }
            else
            {
                ShowMsg("FWCosCreateKeyFile ok!\n");
            }

            //安装外部认证密钥
            uStatus = FWCosAddKey(icdev,
                (byte)2,//外部认证密钥类型
                ref pExKey[0],//密钥值
                16);//密钥文件长度
            if (uStatus != 0)
            {
                ShowMsg("FWCosAddKey[ExKey] error!\n");
                ShowMsg(uStatus.ToString());
                FWCosDeleteFileSys(icdev);//测试结束前删除这个应用
                fw_exit((int)icdev);//
                return;

            }
            else
            {
                ShowMsg("FWCosAddKey[ExKey] ok!\n");
            }

            //安装文件保护密钥
            uStatus = FWCosAddKey(icdev,
                (byte)1,//文件保护密钥类型
                ref pFileProKey[0],//密钥值
                16);//密钥文件长度
            if (uStatus != 0)
            {
                ShowMsg("FWCosAddKey[FileProKey] error!\n");
                ShowMsg(uStatus.ToString());
                FWCosSelecteApp(icdev);
                FWCosVerifyKey(icdev, ref pExKey[0], 16, 2);//验证外部认证密钥
                FWCosDeleteFileSys(icdev);//测试结束前删除这个应用
                fw_exit((int)icdev);//
                return;

            }
            else
            {
                ShowMsg("FWCosAddKey[FileProKey] ok!\n");
            }

            //安装口令
            uStatus = FWCosAddKey(icdev,
                (byte)3,//口令密钥类型
                ref pPin[0],//口令值
                6);//口令长度
            if (uStatus != 0)
            {
                ShowMsg("FWCosAddKey[Pin] error!\n");
                ShowMsg(uStatus.ToString());
                FWCosSelecteApp(icdev);
                FWCosVerifyKey(icdev, ref pExKey[0], 16, 2);//验证外部认证密钥
                FWCosDeleteFileSys(icdev);//
                fw_exit((int)icdev);//
                return;

            }
            else
            {
                ShowMsg("FWCosAddKey[Pin] ok!\n");
            }

            //建立一个二进制一般文件
            uStatus = FWCosCreateBinaryFile(icdev,
            (short)0x0000,//当前所在目录标识
            (short)0x0002,//要建的文件标识
            (short)0x0200,//文件长度
            (byte)1,//数据加密类型：0-明文方式,1-明文+MAC校验，2-密文+MAC校验
            0,//读不需密码
            1,//更新需要口令验证 (1级)
            0);//删除不需密钥(此参数一般无效)
            if (uStatus != 0)
            {
                ShowMsg("FWCosCreateBinaryFile error!\n");
                ShowMsg(uStatus.ToString());
                FWCosSelecteApp(icdev);
                FWCosVerifyKey(icdev, ref pExKey[0], 16, 2);//验证外部认证密钥
                FWCosDeleteFileSys(icdev);//
                fw_exit((int)icdev);//鏂紑杩炴帴
                return;

            }
            else
            {
                ShowMsg("FWCosCreateBinaryFile ok!\n");
            }


            //验证口令
            uStatus = FWCosVerifyKey(icdev,
                ref pPin[0],//口令
                6,//口令长度
                3);//口令类型
            if (uStatus != 0)
            {
                ShowMsg("FWCosVerifyKey error!\n");
                ShowMsg(uStatus.ToString());
                FWCosSelecteApp(icdev);
                FWCosVerifyKey(icdev, ref pExKey[0], 16, 2);//验证外部认证密钥
                FWCosDeleteFileSys(icdev);//
                fw_exit((int)icdev);//
                return;

            }
            else
            {
                ShowMsg("FWCosVerifyKey ok!\n");
            }

            //写(更新)二进制一般文件
            uStatus = FWCosUpdateBinaryFile(icdev,
              (short)0x0002,//文件标识
              (short)0x00,//开始偏移地址
              ref pWriteBuffer[0],//数据值
              (short)lenToRW,//数据长度
              1,//数据加密类型：0-明文方式,1-明文+MAC校验，2-密文+MAC校验
              ref pFileProKey[0],//文件保护密钥
              16);//密钥长度
            if (uStatus != 0)
            {
                ShowMsg("FWCosUpdateBinaryFile error!\n");
                ShowMsg(uStatus.ToString());
                FWCosSelecteApp(icdev);
                FWCosVerifyKey(icdev, ref pExKey[0], 16, 2);//验证外部认证密钥
                FWCosDeleteFileSys(icdev);//
                fw_exit((int)icdev);//
                return;

            }
            else
            {
                ShowMsg("FWCosUpdateBinaryFile ok!\n");
            }

            //读二进制一般文件
            uStatus = FWCosReadBinaryFile(icdev,
                (short)0x0002,//文件标识
                ref pRBuffer[0],
                (short)0x00,//开始偏移地址
                (short)lenToRW,//数据长度
                (Byte)1,//数据加密类型：0-明文方式,1-明文+MAC校验，2-密文+MAC校验
                ref pFileProKey[0],//文件保护密钥
                16);//密钥长度
            if (uStatus != 0)
            {
                ShowMsg("FWCosReadBinaryFile error!\n");
                ShowMsg(uStatus.ToString());
                FWCosSelecteApp(icdev);
                FWCosVerifyKey(icdev, ref pExKey[0], 16, 2);//验证外部认证密钥
                FWCosDeleteFileSys(icdev);//
                fw_exit((int)icdev);//
                return;

            }
            else
            {
                ShowMsg("FWCosReadBinaryFile ok!\n");

                // ShowMsg("%s\n",pRBuffer);
                strMsg = "";
                for (i = 0; i < lenToRW; i++)
                {
                    strMsg += pRBuffer[i].ToString("X2");
                    strMsg += " ";
                }

                ShowMsg(strMsg);
            }

            //***********************************************************************///
            //      值操作
            //**************************************************************************//
            //创建金融目录
            uStatus = FWCosCreateADF(icdev,
                (ushort)0xDF01,//文件标识
                0,//在该目录下建立文件的权限，不需验证密钥
                0,//该目录下删除文件的权限，不需验证密钥
                ref pDirName[0],//名称
                (Byte)10);//长度
            if (uStatus != 0)
            {
                ShowMsg("FWCosCreateADF error!\n");
                ShowMsg(uStatus.ToString());
                FWCosSelecteApp(icdev);
                FWCosVerifyKey(icdev, ref pExKey[0], 16, 2);//验证外部认证密钥
                FWCosDeleteFileSys(icdev);//
                fw_exit((int)icdev);//
                return;

            }
            else
            {
                ShowMsg("\rFWCosCreateADF ok!\n");
            }

            //安装外部认证密钥
            uStatus = FWCosAddKey(icdev,
                (Byte)2,//外部认证密钥类型
                ref pExKey[0],//密钥值
                16);//密钥文件长度
            if (uStatus != 0)
            {
                ShowMsg("FWCosAddKey[ExKey] error!\n");
                ShowMsg(uStatus.ToString());
                FWCosSelecteApp(icdev);
                FWCosVerifyKey(icdev, ref pExKey[0], 16, 2);//验证外部认证密钥
                FWCosDeleteFileSys(icdev);//
                fw_exit((int)icdev);//
                return;

            }
            else
            {
                ShowMsg("FWCosAddKey[ExKey] ok!\n");
            }

            //安装口令
            uStatus = FWCosAddKey(icdev,
                (Byte)3,//口令密钥类型
                ref pPin[0],//口令值
                6);//口令长度
            if (uStatus != 0)
            {
                ShowMsg("FWCosAddKey[Pin] error!\n");
                ShowMsg(uStatus.ToString());
                FWCosSelecteApp(icdev);
                FWCosVerifyKey(icdev, ref pExKey[0], 16, 2);//验证外部认证密钥
                FWCosDeleteFileSys(icdev);//
                fw_exit((int)icdev);//
                return;

            }
            else
            {
                ShowMsg("FWCosAddKey[Pin] ok!\n");
            }

            //安装消费密钥
            uStatus = FWCosAddKey(icdev,
                (Byte)7,//消费密钥类型
                ref pPurchaseKey[0],//密钥值
                16);//密钥长度
            if (uStatus != 0)
            {
                ShowMsg("FWCosAddKey[Purchase] error!\n");
                ShowMsg(uStatus.ToString());
                FWCosSelecteApp(icdev);
                FWCosVerifyKey(icdev, ref pExKey[0], 16, 2);//验证外部认证密钥
                FWCosDeleteFileSys(icdev);//
                fw_exit((int)icdev);//
                return;

            }
            else
            {
                ShowMsg("FWCosAddKey[Purchase] ok!\n");
            }

            //安装圈存密钥
            uStatus = FWCosAddKey(icdev,
                (Byte)5,//圈存密钥类型
                ref pCreditKey[0],//密钥值
                16);//密钥长度
            if (uStatus != 0)
            {
                ShowMsg("FWCosAddKey[Credit] error!\n");
                ShowMsg(uStatus.ToString());
                FWCosSelecteApp(icdev);
                FWCosVerifyKey(icdev, ref pExKey[0], 16, 2);//验证外部认证密钥
                FWCosDeleteFileSys(icdev);//
                fw_exit((int)icdev);//
                return;

            }
            else
            {
                ShowMsg("FWCosAddKey[Credit] ok!\n");
            }

            //验证口令
            uStatus = FWCosVerifyKey(icdev,
                ref pPin[0],//口令
                6,//口令长度
                (char)3);//口令类型
            if (uStatus != 0)
            {
                ShowMsg("FWCosVerifyKey error!\n");
                ShowMsg(uStatus.ToString());
                FWCosSelecteApp(icdev);
                FWCosVerifyKey(icdev, ref pExKey[0], 16, 2);//验证外部认证密钥
                FWCosDeleteFileSys(icdev);//
                fw_exit((int)icdev);//
                return;

            }
            else
            {
                ShowMsg("FWCosVerifyKey ok!\n");
            }

            //圈存（存款）
            uStatus = FWCosCredit(icdev,
                (Byte)0x00,//圈存密钥标识，这里要设为0
                100000,//金额
                ref pTerminal[0],//终端号
                ref pCreditKey[0],//圈存密钥
                16);//密钥长度
            if (uStatus != 0)
            {
                ShowMsg("FWCosCredit error!\n");
                ShowMsg(uStatus.ToString());
                FWCosSelecteApp(icdev);
                FWCosVerifyKey(icdev, ref pExKey[0], 16, 2);//验证外部认证密钥
                FWCosDeleteFileSys(icdev);//
                fw_exit((int)icdev);//
                return;

            }
            else
            {
                ShowMsg("FWCosCredit ok!\n");
            }

            //消费
            uStatus = FWCosPurchase(icdev,
                (Byte)0x01,//消费密钥标识，这里要设为1
                50,//金额
                ref pTerminal[0],//终端号
                ref pPurchaseKey[0],//消费密钥
                16);//密钥长度
            if (uStatus != 0)
            {
                ShowMsg("FWCosPurchase error!\n");
                ShowMsg(uStatus.ToString());
                FWCosSelecteApp(icdev);
                FWCosVerifyKey(icdev, ref pExKey[0], 16, 2);//验证外部认证密钥
                FWCosDeleteFileSys(icdev);//
                fw_exit((int)icdev);//
                return;

            }
            else
            {
                ShowMsg("FWCosPurchase ok!\n");
            }

            //查询当前余额
            uStatus = FWCosGetBalance(
                (UInt32)icdev,
                ref pval[0]);//
            if (uStatus != 0)
            {
                ShowMsg("FWCosGetBalance error!\n");
                ShowMsg(uStatus.ToString());
                FWCosSelecteApp(icdev);
                FWCosVerifyKey(icdev, ref pExKey[0], 16, 2);//验证外部认证密钥
                FWCosDeleteFileSys(icdev);//
                fw_exit((int)icdev);//
                return;

            }
            else
            {
                ShowMsg("FWCosGetBalance ok!\n");
                ShowMsg("balance:" + pval[0].ToString());
            }

            //选择主应用
            FWCosSelecteApp(icdev);

            //验证外部认证密钥
            uStatus = FWCosVerifyKey(icdev,
                ref pExKey[0],//外部认证密钥
                16,//密钥文件长度
                2);
            if (uStatus != 0)
            {
                ShowMsg("FWCosVerifyKey error!\n");
                ShowMsg(uStatus.ToString());
                FWCosDeleteFileSys(icdev);//
                fw_exit((int)icdev);//

            }
            else
            {
                ShowMsg("FWCosVerifyKey ok!\n");
            }


            //测试结束前删除这个应用
            uStatus = FWCosDeleteFileSys(icdev);
            if (uStatus != 0)
            {
                ShowMsg("FWCosDeleteFileSys error!\n");
                ShowMsg(uStatus.ToString());
                fw_exit((int)icdev);//

            }
            else
            {
                ShowMsg("FWCosDeleteFileSys ok!\n");
            }

            fw_exit((int)icdev);//断开连接
        }

    }
}